#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 15:11
# @Author: 刘航
# @Email: xxx@gmail.com
# @File：cule_page.py

"""
线索界面
"""
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
class CulePage(BasePage):
    add_culelocator = (By.XPATH,"/html/body/div[5]/div[2]/div[1]/div/a") #添加线索按钮
    first_cule_locator = (By.XPATH, "/html/body/div[5]/div[3]/div[2]/form/table/tbody/tr[1]")
    first_search_cule_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]")
    first_cule_column_data = (By.TAG_NAME,"td")
    cule_pool_locator = (By.CSS_SELECTOR,".nav-tabs > li:nth-child(2) > a:nth-child(1)") #线索池
    modify_locator = (By.CSS_SELECTOR,".table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(12) > a:nth-child(3)")
    view_locator = (By.CSS_SELECTOR,".table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(12) > a:nth-child(1)")
    select_delete_locator = (By.CSS_SELECTOR, ".check_list")
    action_delete_locator = (By.CSS_SELECTOR, "div.pull-left:nth-child(1) > a:nth-child(1)")
    delete_locator = (By.ID, "delete")
    view_delete_locator = (By.CSS_SELECTOR, '.alert')
    select_locator = (By.ID, "field")
    input_search_locator = (By.ID, "search")
    dosearch_locator = (By.ID, "dosearch")
    change_cule_locator = (By.CSS_SELECTOR,".table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(12) > a:nth-child(2)")
    change_cule_status_locator = (By.XPATH,"/html/body/div[5]/div[2]")
    def add_cule_btn(self):
        """添加线索按钮"""
        self.driver.find_element(*self.add_culelocator).click()
    def first_cule_data(self):
        """第一条线索数据"""
        element = self.driver.find_element(*self.first_cule_locator)
        data = element.find_elements(*self.first_cule_column_data)
        return data
    def first_search_cule_data(self):
        """第一条搜索后的线索数据"""
        element = self.driver.find_element(*self.first_search_cule_locator)
        data = element.find_elements(*self.first_cule_column_data)
        return data

    def cule_pool_btn(self):
        """线索池按钮"""
        self.driver.find_element(*self.cule_pool_locator).click()

    def modify_btn(self):
        """修改接口"""
        self.driver.find_element(*self.modify_locator).click()
    def vies_cule_btn(self):
        """查看线索详情"""
        self.driver.find_element(*self.view_locator).click()
    def select_delete_cule(self):
        """选择要删除的"""
        self.driver.find_element(*self.select_delete_locator).click()
    def action_delete_action(self):
        """操作删除下拉框"""
        self.driver.find_element(*self.action_delete_locator).click()  # 操作删除
    def click_delete_btn(self):
        """点击删除按钮"""
        self.driver.find_element(*self.delete_locator).click()
        self.driver.switch_to.alert.accept()
    def view_delete_status(self):
        """查看删除状态"""
        actual = self.driver.find_element(*self.view_delete_locator).text  # 实际结果
        return  actual
    def handle_select_box(self,select):
        """搜索下拉框选择"""
        element = self.driver.find_element(*self.select_locator)  # 操作下拉框
        Select(element).select_by_visible_text(select)
    def input_search(self,input_company):
        """方框输入公司名称"""
        self.driver.find_element(*self.input_search_locator).send_keys(input_company)  # 输入要搜索的公司
    def click_search(self):
        """点击搜索"""
        self.driver.find_element(*self.dosearch_locator).click()  # 点击搜索
    def change_cule(self):
        """转换线索"""
        self.driver.find_element(*self.change_cule_locator).click()
    def view_change_cule(self):
        """查看线索转客户状态"""
        actual = self.driver.find_element(*self.change_cule_status_locator).text  # 实际结果
        return actual


